<template>
  <div>
    <h2>注册事件监听器</h2>
    <button @click="increment">点我</button>
    <p>You clicked {{ count }} times</p>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'

const count = ref(0)

const increment = () => {
  count.value++
}
const handlekeydown = (e: any) => {
  if (e.key === 'Enter') {
    increment()
  }
}

onMounted(() => {
  window.addEventListener('keydown', handlekeydown)
})

onMounted(() => {
  window.removeEventListener('keydown', handlekeydown)
})
</script>

<style></style>
